
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.runtime.tree.DOTTreeGenerator;
import org.antlr.stringtemplate.StringTemplate;

import wj.*;
import wj.tree.*;


public class Driver{

	public static void main(String[] args)  throws Exception{
		  // create an instance of the lexer
		String portfolioFolder = "Wordy Java Portfolio\\";
	    WJLexer lexer = new WJLexer(new ANTLRFileStream(portfolioFolder+"CharacterCount.wj"));
	        
	    // wrap a token-stream around the lexer
	    CommonTokenStream tokens = new CommonTokenStream(lexer);
	        
	    // create the parser
	    wj.WJParser parser = new WJParser(tokens);
	    CommonTree tree = (CommonTree)parser.parse().getTree();  
	    
	    /*
	    DOTTreeGenerator gen = new DOTTreeGenerator();  
	    StringTemplate st = gen.toDOT(tree);  
	    System.out.println(st); 
	    /**/
	    
	    CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree); 
	    
	    WJTreeWalker walker = new WJTreeWalker(nodes, Scope.GLOBAL_SCOPE);  
	    
	    // get the returned node   
	    WJNode returned = walker.walk();  
	    WJValue returnValue = returned.evaluate();
	    System.out.println(returnValue.equals(WJValue.NULL) ? "" : "Returned: "+returned.evaluate()); 
	    
	}
	
}
